#include "linklist.h"
linklist list_init(void)
{
    linklist head = malloc(sizeof(listnode));
    if (head != NULL)
    {
        head->next = head;
        head->prev = head;
    }
    return head;
}
linklist list_new(int data)
{
    linklist new = malloc(sizeof(listnode));
    if (new != NULL)
    {
        new->next = new;
        new->prev = new;
        new->data=data;
    }
    return new;
}
void list_add_tail(linklist head, linklist new)
{
    new->next = head;
    new->prev = head->prev;
    head->prev->next = new;
    head->prev = new;
}
void list_for_each(linklist head)
{
    linklist p = head->next;
    for(;p!=head;p=p->next)
    {
        printf("%d\t",p->data);
    }
    printf("\n");
}
linklist linklist_del(linklist p)
{
    p->prev->next=p->next;
    p->next->prev=p->prev;
    p->next=p;
    p->prev=p;

    return p;
}
void list_movetail(linklist p,linklist head)
{
    linklist x= linklist_del(p);
    list_add_tail(head,x);
}
void rearrange(linklist head)
{
    linklist k,p;
    k=p=head->prev;
    for(;p!=head;p=p->prev)
    {
        if(p->data%2==1)
        {
            k=p;
        }
        if(p->data%2==0)
        {
            list_movetail(p,head);
            p=k;
        }
    }
}
